package com.ruoyi.demo.controller.app;

import java.util.List;
import java.util.Arrays;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.demo.domain.AuctionSession;
import com.ruoyi.demo.service.IAuctionSessionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 拍卖专场Controller
 *
 * @author metaee
 * @date 2025-03-06
 */
@Api(tags = "小程序-拍卖专场")
@RestController
@RequestMapping("/app/session")
public class AppAuctionSessionController extends BaseController
{
    @Autowired
    private IAuctionSessionService auctionSessionService;

    /**
     * 查询拍卖专场列表
     */
    @ApiOperation("查询拍卖专场列表")
    @GetMapping("/list")
    public TableDataInfo list(AuctionSession auctionSession)
    {
        startPage();
        LambdaQueryWrapper<AuctionSession> wrapper = new LambdaQueryWrapper<>();
        // 根据需要添加查询条件
        if (auctionSession.getSessionName() != null) {
            wrapper.like(AuctionSession::getSessionName, auctionSession.getSessionName());
        }
        if (auctionSession.getStatus() != null) {
            wrapper.eq(AuctionSession::getStatus, auctionSession.getStatus());
        }
        if (auctionSession.getCategoryId() != null) {
            wrapper.eq(AuctionSession::getCategoryId, auctionSession.getCategoryId());
        }
        wrapper.orderByDesc(AuctionSession::getCreateTime);
        List<AuctionSession> list = auctionSessionService.list(wrapper);
        return getDataTable(list);
    }

    /**
     * 获取拍卖专场详细信息
     */
    @ApiOperation("获取拍卖专场详细信息")
    @GetMapping(value = "/{sessionId}")
    public AjaxResult getInfo(@PathVariable("sessionId") Long sessionId)
    {
        return success(auctionSessionService.getById(sessionId));
    }

    /**
     * 新增拍卖专场
     */
    @ApiOperation("新增拍卖专场")
    @Log(title = "拍卖专场", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AuctionSession auctionSession)
    {
        return toAjax(auctionSessionService.save(auctionSession));
    }

    /**
     * 修改拍卖专场
     */
    @ApiOperation("修改拍卖专场")
    @Log(title = "拍卖专场", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AuctionSession auctionSession)
    {
        return toAjax(auctionSessionService.updateById(auctionSession));
    }

    /**
     * 删除拍卖专场
     */
    @ApiOperation("删除拍卖专场")
    @Log(title = "拍卖专场", businessType = BusinessType.DELETE)
    @DeleteMapping("/{sessionIds}")
    public AjaxResult remove(@PathVariable Long[] sessionIds)
    {
        return toAjax(auctionSessionService.removeByIds(Arrays.asList(sessionIds)));
    }
} 